<script type="text/javascript">
    {literal}
    $(document).ready(function() {
        $("#selectedDateFrom").datepicker({ 
            dateFormat: "dd/mm/yy",
            firstDay: 1,
            onSelect: function(date) {
                //$("#selectedDateTo").val(date);
            }
        }); 
        $("#selectedDateTo").datepicker({ 
            dateFormat: "dd/mm/yy",
            firstDay: 1      
        });
    });
    {/literal}
</script>

<h2 class="pageTitle">Protocol about work execution and goods delivery</h2>

<div class="menu-list">
    <form action="{$data.root}?input=protocol" method="post">
        Client: &nbsp;
        <select size="1" name="selectedClient" onchange="userListOfClient(this.value)">
            <option value="">Please select</option>
            {foreach from=$data.clients item="client"}
                <option {if $smarty.session.user.user_type_id!=$smarty.const.USER_TYPE_CLIENT && $client.bad_payer==1}class="badPayer"{/if} {if $data.prefill.client==$client.klient_id}selected="selected"{/if} value="{$client.klient_id}">{$client.name}</option>
            {/foreach}
        </select>&nbsp;
        Date from: &nbsp;
        <input name="selectedDateFrom" value="{$data.prefill.dateFrom}" type="text"  id="selectedDateFrom" />
        Date to: &nbsp;
        <input name="selectedDateTo" value="{$data.prefill.dateTo}" type="text"  id="selectedDateTo" />
        User: &nbsp;
        <select id="selectedUser" size="1" name="selectedUser">
            <option value="">Please select</option>
            {foreach from=$data.users item="user"}
                <option {if $data.prefill.user==$user.users_id}selected="selected"{elseif $user.prefered==1}selected="selected"{/if} value="{$user.users_id}">{$user.name} {$user.surname}</option>
            {/foreach}
        </select>&nbsp;
        <input type="submit" value="show" />
    </form>
</div>
{if  $data.records|@count == 0} 
    No records.
{else}
    <div style="margin: 1em;">
        <a target="_blank" href="{$data.root}print.php?input=protocol&amp;selectedClient={$data.prefill.client}&amp;selectedDateFrom={$data.prefill.dateFrom}&amp;selectedDateTo={$data.prefill.dateTo}&amp;selectedUser={$data.prefill.user}" class="basicButton">Print this protocol</a>
    </div>
    <table class="protocol-list">
        <tr>
            <td colspan="8">
                <table style="width: auto">
                    <tr>
                        <td rowspan="4">
                            <img src="{$data.root}images/alfac_no_text.png" width="200" />
                        </td>
                        <td colspan="2" style="padding-left: 10px;">
                            <h1 style="font-size: 18px; margin: 0px 0 5px 0; padding: 0">Alfa Centauri spol. s r.o.</h1>
                            Pri strelnici 3, 821 04 Bratislava<br/>
                        </td>
                    </tr>
                    <tr>
                        <td style="padding-left: 10px;">Tel.: + 421 243 427 175</td>
                        <td>Fax: + 421 243 427 175</td>
                    </tr>
                    <tr>
                        <td style="padding-left: 10px;">Internet: www.alfac.sk </td>
                        <td>E-mail:  office@alfac.sk </td>
                    </tr>
                    <tr>
                        <td style="padding-left: 10px;">Kontaktná osoba:  {$data.contact_info.name} {$data.contact_info.surname}</td>
                        <td>E-mail: {$data.contact_info.email}</td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <th colspan="8">
                <br/>
                <br/>
            </th>
        </tr>
        <tr>
            <th colspan="8" class="left-align">
        <h1 style="font-size: 18px; margin: 0px; padding: 0">PROTOKOL o vykonaní práce a dodaní tovaru</h1>
        <br/>
        <br/>
    </th>
</tr>
<tr>
    <th colspan="8" class="left-align" style="font-size: 14px">
        Pre {$data.client_info.fullName}, IČO: {$data.client_info.ICO}<br/>
        Dátum: 
        {if $data.prefill.dateFrom != $data.prefill.dateTo}
            {$data.prefill.dateFrom} - {$data.prefill.dateTo}
        {else}
            {$data.prefill.dateFrom}
        {/if}
        <br/>
        <br/>
    </th>
</tr>
{foreach from=$data.records key="name" item="recs"}
    <tr>
        <td style="padding: 10px 0" colspan="8" class="left-align"><strong>{$name}:</strong></td>
    </tr>
    <tr>
        <td class="left-align" style="color:#0F192A; width: 300px; border-bottom: 1px solid gainsboro">Popis</td>
        <td class="left-align" style="color:#0F192A; border-bottom: 1px solid gainsboro">Dátum</td>
        <td class="left-align" style="color:#0F192A; border-bottom: 1px solid gainsboro">Sadzba</td>
        <td class="left-align" style="color:#0F192A; border-bottom: 1px solid gainsboro">Množstvo</td>
        <td class="left-align" style="color:#0F192A; border-bottom: 1px solid gainsboro">Jednotková cena</td>
        <td class="left-align" style="color:#0F192A; border-bottom: 1px solid gainsboro">Cena bez DPH</td>
        <td class="left-align" style="color:#0F192A; border-bottom: 1px solid gainsboro">Cena s DPH</td>
        <td class="left-align" style="color:#0F192A; border-bottom: 1px solid gainsboro">Odovzdal</td>
    </tr>
    {foreach from=$recs item="record" key="k"}
        <tr>
            <td class="left-align" style="width: 300px;">{$record.description}</td>
            <td class="left-align">{$record.date_formated}</td>
            <td class="left-align">{$record.tariff_info.title}</td>
            <td class="left-align">{$record.amount}</td>
            <td class="left-align">{$record.unit_price|round:"2"} €</td>
            <td class="left-align">{$record.withoutDph|round:"2"} €</td>
            <td class="left-align">{$record.withDph|round:"2"} €</td>
            <td class="left-align">{$record.user_info.name} {$record.user_info.surname}</td>
        </tr>
    {/foreach}
    <tr>
        <td colspan="5" class="left-align" style="border-top: 1px solid gray;color:#0F192A"><b>Suma - {$name}:</b></td>
        <td class="left-align" style="border-top: 1px solid gray;color:#0F192A"><b>{$data.sums.$name.withoutDph|round:"2"} €</b></td>
        <td class="left-align" style="border-top: 1px solid gray;color:#0F192A"><b>{$data.sums.$name.withDph|round:"2"} €</b></td>
        <td class="left-align" style="border-top: 1px solid gray;color:#0F192A"></td>
    </tr>
{/foreach}
<tr>
    <th colspan="8" class="left-align">
        <br/>
        <br/>
    </th>
</tr>
<tr>
    <td colspan="5" class="left-align" style="font-size: 14px; padding: 10px 0; border: 1px solid black"><b>Celková suma:</b></td>
    <td class="left-align" style="font-size: 14px; padding: 10px 0; border: 1px solid black "><b>{$data.total_sums.withoutDph|round:"2"} €</b></td>
    <td colspan="2" class="left-align" style="font-size: 14px; padding: 10px 0; border: 1px solid black "><b>{$data.total_sums.withDph|round:"2"}  €</b></td>
</tr>
<tr>
    <th colspan="8" class="left-align">
        <br/>
        <br/>
    </th>
</tr>
<tr>
    <td colspan="4">
        <b>Odovzdal:</b><br/>
        Meno a priezvisko: {$smarty.session.user.profile.name} {$smarty.session.user.profile.surname} 
    </td>
    <td colspan="4">
        <b>Prevzal/a:</b><br/>
        Meno a priezvisko: {$data.user_info.name} {$data.user_info.surname}
    </td>
</tr>
<tr>
    <th colspan="8" class="left-align">
        <br/>
        <br/>
    </th>
</tr>
<tr>
    <td colspan="4"><br/>Podpis: ................................................</td>
    <td colspan="4"><br/>Podpis: ................................................</td>
</tr>
</table>
{/if} 
